from flask import render_template
from info.food_models import Category, Food
from info.modules.index import index_blu


@index_blu.route("/")
def index():

    # 菜品分类
    category_object_lists = Category.query.all()
    category_list = []
    for categorys in category_object_lists:
        category_list.append(categorys.to_dict())

    # 热门菜
    hot_food_object_lists = Food.query.order_by(Food.sales.desc()).paginate(1, 6, False)
    hot_food_lists = hot_food_object_lists.items

    data = {
        'categories': category_list,
        'hot_foods': hot_food_lists
    }

    return render_template("food/index.html", data=data)